﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <script src="../../js/load.js"></script>
</head>

<body>
<div id="container">
    <div id="formcontainer">
        <form class="layui-form layui-form-pane" id="editform" lay-filter="editform">
            <div class="layui-row">
                <div class="layui-col-xs12">
                    <div class="layui-form-item">
                        <label class="layui-form-label">所属分类</label>
                        <div class="layui-input-block">
                            <div id="groupGuid">

                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs6">
                    <div class="layui-form-item">
                        <label class="layui-form-label required">项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="projectName" autocomplete="off" class="layui-input required">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <div class="layui-form-item">
                        <label class="layui-form-label required">服务名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="serviceName" autocomplete="off" class="layui-input required">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">端口号</label>
                        <div class="layui-input-block">
                            <input type="text" name="depolyPort" autocomplete="off" class="layui-input number">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <div class="layui-form-item">
                        <label class="layui-form-label required">排序</label>
                        <div class="layui-input-block">
                            <input type="text" name="sortNum" autocomplete="off" class="layui-input number" value="0">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs12">
                    <div class="layui-form-item">
                        <label class="layui-form-label">JDK路径</label>
                        <div class="layui-input-block">
                            <input type="text" name="javaHome" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs12">
                    <div class="layui-form-item">
                        <label class="layui-form-label">服务依赖</label>
                        <div class="layui-input-block">
                            <div id="dependService">

                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs12">
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">前置参数</label>
                        <div class="layui-input-block">
                            <textarea name="depolyBeforeParam" autocomplete="off" class="layui-textarea">-Dfile.encoding=UTF-8</textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs12">
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">后置参数</label>
                        <div class="layui-input-block">
                            <textarea name="depolyAfterParam" autocomplete="off" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs12">
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">部署备注</label>
                        <div class="layui-input-block">
                            <textarea name="depolyRemark" autocomplete="off" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <div id="opcontainer">
        <button class="layui-btn" onclick="HandleSave()">确认</button>
        <button class="layui-btn layui-btn-primary" onclick="HandleClose()">关闭</button>
    </div>
</div>
</body>
<script>
    var FormDetail = null;
    var dependService = null;
    var groupGuid = null;
    $(function () {
        LoadDetail();
    })

    function LoadDetail() {
        var param = {
            projectID: GetUrlParam("projectID")
        }
        SetForm("editform", "api/project/detail", param, function (data) {
            FormDetail = data;
            var serviceList = "";
            if(data.dependService){
               serviceList = data.dependService.split("|")
            }
            var groupList = "";
            if(data.groupGuid){
              groupList = data.groupGuid.split("|")
            }
            initService(serviceList);
            initGroup(groupList);
        })
    }

    function HandleSave() {
        SubmitForm('editform', "api/project/update", BeforeSubmit, FormDetail, function (result, status) {
            if (result.code == 0) {
                OpenSuccess('保存成功', function (params) {
                    CloseDialog();
                })

            } else {
                OpenFail(result.msg);
            }
        })
    }

    function BeforeSubmit(data) {
        var serviceList = dependService.getValue('name');
        data.dependService = serviceList.join("|");
        var groupList = groupGuid.getValue('value');
        data.groupGuid = groupList.join("|");
        return true;
    }


    function HandleClose() {
        CloseDialog();
    }

    function initService(defaultValue) {
        var param = {
            pageIndex:1,
            pageSize:500
        }
        HttpPost(JSON.stringify(param), 'api/service/list', function (result) {
            if (result.code == 0) {
                var serviceList = result.data.rows;
                var data = [];
                for (var i=0;i<serviceList.length;i++){
                    if(defaultValue.indexOf(serviceList[i].serviceName)>=0){
                        data.push({name: serviceList[i].serviceName, value: serviceList[i].serviceName,selected: true})
                    }else{
                       data.push({name: serviceList[i].serviceName, value: serviceList[i].serviceName})
                    }
                }
                dependService = xmSelect.render({
                    el: '#dependService',
                    filterable: true,
                    data: data
                })
            }
        })

    }

    function initGroup(defaultValue) {
        var param = {
        }
        HttpPost(JSON.stringify(param), 'api/group/list', function (result) {
            if (result.code == 0) {
                var groupList = result.data.obj;
                var data = [];
                for (var i=0;i<groupList.length;i++){
                    if(defaultValue.indexOf(groupList[i].groupID)>=0){
                       data.push({name: groupList[i].groupName, value: groupList[i].groupID,selected: true})
                    }else{
                      data.push({name: groupList[i].groupName, value: groupList[i].groupID})
                    }
                }
                groupGuid = xmSelect.render({
                    el: '#groupGuid',
                    filterable: true,
                    data: data
                })
            }
        })
    }

</script>

</html>